<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>业务处理</title>
    <link rel="stylesheet" href="/css/element.css">
    <link rel="stylesheet" href="/css/base.css">
</head>

<body>
<div id="business">

    <div style="color: black; font-size: 20px; margin: 10px 0"> <span >业务处理</span></div>
    <div style="height: 1px; background-color: white"></div>
    <el-input v-model="search" style="width: 20%;" suffix-icon="el-icon-search"
              placeholder="请输入业务名称或者编号按回车搜索" @keyup.enter.native="loadTable"></el-input>
    <el-button @click="createbusiness" type="primary" size="mini" style="margin: 10px 0">新建业务</el-button>
    <!--                <el-button @click="exp" type="primary" size="mini" style="margin: 10px 0">导出</el-button>-->
    <el-table
            :data="tableData"
            baorder
            style="width: 100%">
        <el-table-column
                v-for="item in props"
                :prop="item.prop"
                :label="item.label"

        >
        </el-table-column>
        <el-table-column
                fixed="right"
                label="操作"
                width="100">
            <template slot-scope="scope">
                <el-button @click="edit(scope.row)" type="text">处理</el-button>
                <el-popconfirm
                        @onConfirm="returnback(scope.row.id)"
                        title="确定驳回？"
                >
                    <el-button type="text" slot="reference">驳回</el-button>
                </el-popconfirm>
            </template>
        </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div style="background-color: white">
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNum"
                :page-sizes="[5, 10, 20, 40]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>
    <el-dialog title="新建业务" :visible.sync="dialogFormVisible" width="70%"
               close-on-click-modal="false" close-on-press-escape="false" show-close="false">
        <el-table
                :data="tableData1"
                border
                style="width: 100%">
            <el-table-column
                    v-for="item in props1"
                    :prop="item.prop"
                    :label="item.label"

            >
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    width="100">
                <template slot-scope="scope">
                    <el-button @click="createt(scope.row)" type="text">新建</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div style="background-color: white">
            <el-pagination
                    @size-change="handleSizeChange1"
                    @current-change="handleCurrentChange1"
                    :current-page="pageNum1"
                    :page-sizes="[5, 10, 20, 40]"
                    :page-size="pageSize1"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total1">
            </el-pagination>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">关 闭</el-button>
            <!--                        <el-button type="primary" @click="save">新 建</el-button>-->
        </div>

    </el-dialog>

</div>

</body>
<script src="/js/vue.min.js"></script>
<script src="/js/jquery.min.js"></script>
<script src="/js/element.js"></script>
<script src="/js/base.js"></script>

<script type="text/javascript">
    function user() {
        let urlBase = "/business";
        new Vue({
            el: "#business",
            data(){
                return{
                    user: {},
                    tableData: [],
                    tableData1: [],
                    pageNum: 1,
                    pageNum1:1,
                    pageSize: 10,
                    pageSize1: 5,
                    total: 0,
                    total1:0,
                    dialogFormVisible: false,
                    entity: {},
                    isCollapse: false,
                    search: '',
                    options: [],
                    props: [{"label":"业务序号","prop":"id"},{"label":"业务名称","prop":"bussnessname"}],
                    props1: [{"label":"业务编号","prop":"id"},{"label":"业务名称","prop":"bussnessname"},{"label":"业务描述","prop":"description"}]

                }
            },

            created() {
                this.user = sessionStorage.getItem("user") ? JSON.parse(sessionStorage.getItem("user")) : {};
                console.log(this.user)
                this.loadTable();
            },
            mounted(){
                // this.initpage();
            },
            methods: {
                // initpage(){
                //     $.ajax({
                //         url: "/user/getuser",
                //         type: type,
                //         contentType: "application/json",
                //         data: JSON.stringify(this.user)
                //     }).then(res =>{
                //         console.log(this.user);
                //     })
                // },
                createt(data){
                    console.log(urlBase + "initprocess&bussinessnum="+data.id);
                    $.get(urlBase + "initprocess?&bussinessnum="+data.id).then(res => {
                        // alert(res.data.frontpath);
                        console.log(res);
                        // location.href = "/" + res.data.frontpath+"?currentbussnessnum=" + res.data.currentbussnessnum;
                    })
                },
                handleCollapse() {
                    this.isCollapse = !this.isCollapse;
                },

                loadTable() {

                    $.get(urlBase + "/page?pageNum=" + this.pageNum + "&pageSize=" + this.pageSize + "&name=" + this.search+"&doctorid=" + this.user.jobnum).then(res => {
                        this.tableData = res.data.records;
                        console.log("tabledata")
                        console.log(res.data.records)
                        this.total = res.data.total;
                    })
                    // console.log(this.tableData)

                    $.get("/role").then(res => {
                        this.options = res.data;
                    })
                },
                // exp() {
                //     window.open(urlBase + "/export");
                // },
                handleSizeChange(pageSize) {
                    this.pageSize = pageSize;
                    this.loadTable();
                },
                handleCurrentChange(pageNum) {
                    this.pageNum = pageNum;
                    this.loadTable();
                },handleSizeChange1(pageSize) {
                    this.pageSize1 = pageSize;
                    this.createbusiness();
                },
                handleCurrentChange1(pageNum) {
                    this.pageNum1 = pageNum;
                    this.createbusiness();
                },
                //找到该用户所能创建的业务,传入的是user.jobnum
                createbusiness() {
                    $.get(urlBase + "/businesscreatemsg?pageNum=" + this.pageNum1 + "&pageSize=" + this.pageSize1 + "&doctorid=" + this.user.jobnum).then(res => {
                        this.tableData1 = res.data.records;
                        this.total1 = res.data.total;
                        console.log(this.tableData1);
                    })

                    this.dialogFormVisible = true;
                },

                edit(obj) {
                    console.log(obj)
                    location.href = obj.frontpath+"?currentbussnessnum="+obj.id;
                },
                returnback(id) {
                    $.ajax({
                        url: urlBase+"reject",
                        type: "POST",
                        contentType: "application/json",
                        data: JSON.stringify({
                            currentbussnessnum:id,
                            rejectmsg:"reject"
                        })
                    }).then(res => {
                        if (res.code === '0') {
                            this.$message({
                                message: "成功",
                                type: "success"
                            })
                            this.loadTable();
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            })
                        }
                    })
                }
            }
        })

    }


    user();
</script>



</html>